package com.guanyong.services;

import com.guanyong.dao.IMerchantDaoMapper;
import com.guanyong.dao.IMerchantLogDaoMapper;
import com.guanyong.model.MerchantLogModel;
import com.guanyong.model.MerchantModel;
import com.guanyong.utils.Comm.DateExt;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mxk on 2017/9/20.
 */
@Service
public class MerchantService {


    @Autowired
    IMerchantDaoMapper iMerchantDaoMapper;


    @Autowired
    IMerchantLogDaoMapper iMerchantLogDaoMapper;

    public ResultObject<MerchantModel> GetMerchantModelByAk(String ak) {
        ResultObject<MerchantModel> resultObject=new ResultObject<MerchantModel>();
        MerchantModel merchantModel=iMerchantDaoMapper.selectByPrimaryKey(ak);
        resultObject.setResult(merchantModel);
        return resultObject;
    }


    public HashMap<String,Object> GetMerchantModelList(String  name,
                                                  Integer pno,
                                                  Integer pagesize,
                                                  Integer allcount){
        HashMap<String,Object> hashMap=new HashMap();
        if (allcount<0){
            Integer count=iMerchantDaoMapper
                    .SelectMerchantListCount(name);
            hashMap.put("count",count);
        }
        else {
            hashMap.put("count",allcount);
        }
        List<MerchantModel> merchantModels
                =iMerchantDaoMapper.SelectMerchantList(name,(pno-1)*pagesize,
                pagesize);
        hashMap.put("list",merchantModels);
        return hashMap;
    }




    public HashMap<String,Object> GetMerchantLogModelList(String  ak,String year,String moth,
                                                          String name,
                                                       Integer pno,
                                                       Integer pagesize,
                                                       Integer allcount){
        HashMap<String,Object> hashMap=new HashMap();

        String btime=year+"-"+moth+"-01";
        Date bDate= DateExt.StrToDate2(btime);
        String etime=DateExt.DateAddMonth(bDate);


        if (allcount<0){
            Integer count=iMerchantLogDaoMapper
                    .SelectMerchantLogListCount(ak,btime,etime,name);
            hashMap.put("count",count);
        }
        else {
            hashMap.put("count",allcount);
        }
        List<MerchantModel> merchantModels
                =iMerchantLogDaoMapper.SelectMerchantLogList(ak,btime,etime,name,(pno-1)*pagesize,
                pagesize);
        hashMap.put("list",merchantModels);
        return hashMap;
    }


    public  List<HashMap<String,Integer>>  GetAllCountLog(String ak,String year,String moth,
                                                          String name){
        String btime=year+"-"+moth+"-01";
        Date bDate= DateExt.StrToDate2(btime);
        String etime=DateExt.DateAddMonth(bDate);
        return iMerchantLogDaoMapper.getAllCount(ak,btime,etime,name);
    }


    public   List<HashMap<Integer, Integer>> GetCountByYear(String akid){
        return  iMerchantLogDaoMapper.GetResultGourpByYear(akid);

    }


    public   List<HashMap<String, Integer>> GetCountByFilmName(String akid){
        return  iMerchantLogDaoMapper.GetResultGourpByObjectid(akid);

    }

    public   List<HashMap<String, Integer>> GetCountByTimeH(String akid,String btime,String etime){
        return  iMerchantLogDaoMapper.GetResultGourpByTimeDay(akid,btime,etime);

    }
}
